package homework.mission3;

import java.util.HashMap;

public class CountNum {
    public static void main(String[] args) {
        String str = "123,456,789,123,456";

        // 把字符串转成字符串数组
        String[] numArr = str.split(",");

        HashMap<String, Integer> map  = new HashMap<String, Integer>();

        for (String key : numArr) {
            Integer value = map.get(key);

            if(value == null) {
                map.put(key, 1);
            } else {
                map.put(key, value + 1);
            }
        }
        
        // 遍历 map
        for (String key : map.keySet()) {
            System.out.println(key + " 出现了 " + map.get(key) + " 次");
        }
    }
}
